package com.walkline.weibo.dao;

import java.util.Vector;
import org.json.me.JSONArray;
import org.json.me.JSONException;
import org.json.me.JSONObject;
import com.walkline.util.Function;
import com.walkline.weibo.WeiboException;
import com.walkline.weibo.WeiboSDK;
import com.walkline.weibo.inf.Comment;
import com.walkline.weibo.inf.CommentWrapper;

public class WeiboCommentWrapper extends WeiboObject implements CommentWrapper
{
	private int _total_number = 0;
	private Vector _comments = new Vector();

	public WeiboCommentWrapper(WeiboSDK weibo, JSONObject jsonObject) throws WeiboException
	{
		super(weibo, jsonObject);

		JSONObject commentWrapper = jsonObject;
		if (commentWrapper != null)
		{
			_total_number = commentWrapper.optInt("total_number");

			JSONArray comments = commentWrapper.optJSONArray("comments");
			if (comments != null)
			{
				JSONObject commentObject;
				Comment comment;

				for (int i=0; i<comments.length(); i++)
				{
					try {
						commentObject = (JSONObject) comments.get(i);

						comment = new WeiboComment(weibo, commentObject);
						if (comment != null) {_comments.addElement(comment);}
					} catch (JSONException e) {Function.errorDialog(e.toString());}
				}
			}
		}
	}

	public int getTotalNumber() {return _total_number;}

	public Vector getComments() {return _comments;}
}